package com.chengn.paramtest;

import com.chengn.factory.MyThreadFactory;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CoreParamTest {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(5,
                8,
                0L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(2),
                new MyThreadFactory());

        int taskNum = 7;

        for(int i = 1; i <= taskNum; ++i){
            final int j = i;
            pool.execute(() -> {
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (Exception ex) {
                    // todo
                }
                Thread thread = Thread.currentThread();
                System.out.println("任务： " + j + "------" + "线程名字" + thread.getName() + "----活跃线程数" + pool.getActiveCount());
            });
        }
    }
}
